/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * @author Administrator
 * Date: 2010-7-6 上午11:05:19
 */
package com.ccxe.manage.service.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ccxe.manage.util.StringValueValid;

/**
 * @author wangyaoxi
 * 
 */
public class RoleRequestService extends BaseRequestService {

	private RoleDaoService daoService = new RoleDaoService();
	private RolePageService pageService;
	private String action;

	public RoleRequestService(HttpServletRequest req, HttpServletResponse resp) {
		this.request = req;
		this.response = resp;
		pageService = new RolePageService(req, resp);
	}

	@Override
	public void buildParameters() {
		reciveAndSendParameter();
	}

	/**
	 * 接收并发送参数
	 */
	private void reciveAndSendParameter() {
		action = request.getParameter("action");
		if (StringValueValid.isNullOrEmpty(action)) {
		} else {
			addOrUpdateOrDeleteOperate();
		}
	}

	private void addOrUpdateOrDeleteOperate() {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String discription = request.getParameter("discription");
		if (StringValueValid.isNotNullAndEmpty(id)) {
			if ("add".equals(action)) {

			} else if ("update".equals(action)) {
				daoService.update(new String[] { name, discription, id });
			}
		} else {
			// 删除操作
			deleteData();
			pageService.buildParameters();
		}
	}

	/**
	 * 删除一条数据
	 */
	private void deleteData() {
		// 前台action=deleteData ,并且接收 hiddenId参数
		String hiddenId = request.getParameter("hiddenId");
		RoleDeleteTransactionService teanService = new RoleDeleteTransactionService(
				hiddenId);
		if (StringValueValid.isNotNullAndEmpty(hiddenId)) {
			teanService.processTransaction();
		}
	}

	@Override
	protected String buildJspUrl() {
		return "/jsp/role/list.jsp?date="+Math.random();
	}
}
